<?php
/**
 * User: hufeng
 * Date: 2016/12/25
 * Desc：短信类库
 */
namespace App\Common\Util;
use SasPHP\Config;
use Aliyun\DySDKLite\SignatureHelper;

class Sms{

    public function smsSend($tel,$code,$tplType){
        require_once(BASEDIR.'/vendor/alidayu/SignatureHelper.php');
        $confObj = new Config(BASEDIR.'/App/Common/Conf');
        $conf = $confObj->offsetGet('config');
        $aldyConf = $conf['ALIDAYU'];
        $params = array ();
        $accessKeyId = $aldyConf['app_key'];
        $accessKeySecret = $aldyConf['app_secret'];
        $params["PhoneNumbers"] = $tel;
        $params["SignName"] = "神都科技";
        $params["TemplateCode"] = $aldyConf[$tplType];
        $params['TemplateParam'] = Array (
            "code" => $code,
            "product" => "guhai"
        );
        $params['OutId'] = '12345';
        $params['SmsUpExtendCode'] = "1234567";
        if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
            $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
        }
        $helper = new SignatureHelper();
        $content = $helper->request(
            $accessKeyId,
            $accessKeySecret,
            "dysmsapi.aliyuncs.com",
            array_merge($params, array(
                "RegionId" => "cn-hangzhou",
                "Action" => "SendSms",
                "Version" => "2017-05-25",
            ))
        );
        return $content;
    }
}